﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;
using BasicLight.Unleashed;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace BasicLight.Client.Includes
{
    public sealed partial class Scene : UserControl
    {
        public Scene()
        {
            this.InitializeComponent();
            this.ControlBind();
            this.EventBind();
        }

        private void ControlBind()
        {
            this.Height = Window.Current.Bounds.Height;
            this.Width = Window.Current.Bounds.Width;

            Canvas.SetTop(this, -Window.Current.Bounds.Height);

            RotateLogo();
        }

        private void EventBind()
        {
            Window.Current.SizeChanged += (sender, e) =>
            {
                this.ControlBind();
            };
        }

        public void Hide()
        {
            CircleEase ease = new CircleEase();
            ease.EasingMode = EasingMode.EaseOut;

            DoubleAnimation canvasTop = new DoubleAnimation();
            canvasTop.To = -Window.Current.Bounds.Height;
            canvasTop.Duration = new TimeSpan(0, 0, 0, 0, 800);
            canvasTop.EasingFunction = ease;
            Storyboard.SetTarget(canvasTop, this);
            Storyboard.SetTargetProperty(canvasTop, "(Canvas.Top)");

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(canvasTop);
            storyboard.Begin();
        }

        public void Show()
        {
            CircleEase ease = new CircleEase();
            ease.EasingMode = EasingMode.EaseOut;

            DoubleAnimation canvasTop = new DoubleAnimation();
            canvasTop.To = 0;
            canvasTop.Duration = new TimeSpan(0, 0, 0, 0, 800);
            canvasTop.EasingFunction = ease;
            Storyboard.SetTarget(canvasTop, this);
            Storyboard.SetTargetProperty(canvasTop, "(Canvas.Top)");

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(canvasTop);
            storyboard.Begin();
        }

        private void CloseClick(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        private void RotateLogo()
        {
            DoubleAnimation rotateAnimation = new DoubleAnimation();
            rotateAnimation.Duration = new TimeSpan(0, 0, 0, 5);
            rotateAnimation.From = 0;
            rotateAnimation.To = 360;
            rotateAnimation.RepeatBehavior = RepeatBehavior.Forever;

            Storyboard.SetTarget(rotateAnimation, this.radioLogoRotate);
            Storyboard.SetTargetProperty(rotateAnimation, "(RotateTransform.Angle)");

            Storyboard radioLogoRotateStoryboard = new Storyboard();
            radioLogoRotateStoryboard.Children.Add(rotateAnimation);
            radioLogoRotateStoryboard.Begin();
        }
    }
}
